// 泛型
function createArray<T>(length: number, value: T): Array<T> {
  const result = [];
  for (let i = 0; i < length; i++) {
      result[i] = value;
  }
  return result;
}

const arr1 = createArray(10, 'hello')
const arr2 = createArray(10, true)


interface Length {
  length: number
}

function loggingIdentity<T extends Length>(arg: T): T {
  console.log(arg.length);
  return arg;
}

loggingIdentity([])

type Undefinable<T> = undefined | T;
// type Undefinable = undefined | number;

let id: Undefinable<number>  = undefined;
id = 1

let str: Undefinable<string> = undefined
str = 'string'